package com.example.lifecycle

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button

class MainActivity : AppCompatActivity() {
    var myLifeCycleListener:MyLifeCycleListener = MyLifeCycleListener()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        myLifeCycleListener = MyLifeCycleListener(this,object :MyLifeCycleListener.OnLocationChangeListener{
            override fun onChange(lat: Double, long: Double) {
                //show Loc
            }
        })
        lifecycle.addObserver(myLifeCycleListener)
        initViews()
    }

    private fun initViews(){
        findViewById<Button>(R.id.button)?.setOnClickListener {
            startService(Intent(this,MyLifeCycleService::class.java))
        }
        findViewById<Button>(R.id.button2)?.setOnClickListener {
            stopService(Intent(this,MyLifeCycleService::class.java))
        }
    }
}